const commentModel = require('../models/newsComments.js')

exports.list = async (req, res, next) => {
	try {
		const { newsid } = req.params
		const comments = await commentModel.getCommentByNewsId(newsid, req.query)
		res.status(200).json(comments)
	} catch(err) {
		next(err)
	}
}

exports.create = async (req, res, next) => {
	try {
		const id = await commentModel.addComment(req.body)
		const comment = await commentModel.getCommentById(id)
		res.status(201).json(comment)
	} catch (err) {
		next(err)
	}
}